package com.grf.hadoop.temp_grouping;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class TempCroupingComparator extends WritableComparator {

    protected  TempCroupingComparator() {
        super(TempBean.class, true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        int res;
        TempBean aBean = (TempBean) a;
        TempBean bBean = (TempBean) b;
        if (aBean.getYear().substring(0,4).compareTo(bBean.getYear().substring(0,4)) > 0) {
            res = 1;
        } else if (aBean.getYear().substring(0,4).compareTo(bBean.getYear().substring(0,4)) < 0){
            res = -1;
        } else {
            res = 0;
        }
        return res;
    }
}
